package top.lyc829.mymusic

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import com.hjq.permissions.XXPermissions
import com.lzx.starrysky.GlobalPlaybackStageListener
import com.lzx.starrysky.StarrySky
import com.lzx.starrysky.manager.PlaybackStage
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import com.tencent.mmkv.MMKV

/**
 * @Author lyc
 * @create 2021-06-28 23:29
 */
class MyApp : Application(), ViewModelStoreOwner {

    private val mAppViewModelStore: ViewModelStore by lazy { ViewModelStore() }

    companion object {
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
    }

    override fun onCreate() {
        super.onCreate()
        context = applicationContext

        MMKV.initialize(this)

        // 当前项目是否已经适配了分区存储的特性
        XXPermissions.setScopedStorage(true)

        StarrySky.init(this)
            .apply()

        val strategy = PrettyFormatStrategy.newBuilder()
            .showThreadInfo(false) // 是否显示线程信息，默认为ture
            .methodCount(1)  // 显示的方法行数
            .methodOffset(0) // 隐藏内部方法调用到偏移量
            .tag("tag")
            .build()
        Logger.addLogAdapter(object : AndroidLogAdapter(strategy) {
            override fun isLoggable(priority: Int, tag: String?): Boolean {
                return BuildConfig.DEBUG
            }
        })
    }

    override fun getViewModelStore(): ViewModelStore {
        return mAppViewModelStore
    }

}